package com.mmall.Concurrency;

import com.mmall.Concurrency.example.ThreadLocal.RequestHolder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 拦截器处理完之后，则进行清除
 */
@Slf4j
public class HttpInterceptor  extends HandlerInterceptorAdapter{
    @Override
    //接口处理前

    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        log.info("preHandle");

        return true;  //如果返回false，则后面接口无法继续处理
    }
    //接口处理后
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        RequestHolder.remove();
        log.info("afterCompletion");
        return ;//接口已经处理完
    }
}
